package edu.calvin.djs32.cs214.interpreters.calculator.primitives;

import ovm.polyd.PolyD;
import edu.calvin.cs214.hobbes2008.HobbesTIR;
import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.TupleTIR;
import edu.calvin.djs32.cs214.interpreters.calculator.Applicable;
import edu.calvin.djs32.cs214.interpreters.calculator.ICalculator;

public class TRefPrimitive implements Applicable, ITRefPrimitive {

	public HobbesTIR apply(ICalculator calc, HobbesTIR... tir) {
		ITRefPrimitive dispatcher = PolyD.build(ITRefPrimitive.class, this);
		return dispatcher.tref(tir[0], tir[1]);
	}

	public HobbesTIR tref(TupleTIR tir1, IntegerTIR tir2) {
		return tir1.getElement(tir2.getInt());
	}

	public HobbesTIR tref(HobbesTIR tir1, HobbesTIR tir2) {
		throw new IllegalStateException("unimplemented!");
	}

}
